package com.luoy.websocket;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author LUOYUAN
 * @date 2018-12-04-13:21
 */

@Data
@Slf4j
public class WebSocketReturnBase<T> {

    private int code;
    private String msg;
    private T data;
    private String path;
    private String type;

    public static <W> WebSocketReturnBase<W> succeed(String path, W w) {
        WebSocketReturnBase<W> returnBase = new WebSocketReturnBase<>();
        returnBase.setCode(Constants.SUCCESS_CODE);
        returnBase.setData(w);
        returnBase.setMsg(Constants.SUCCESS_MSG);
        returnBase.setPath(path);
        returnBase.setType("request");
        return returnBase;
    }


    public static WebSocketReturnBase succeed(String path) {
        WebSocketReturnBase returnBase = new WebSocketReturnBase<>();
        returnBase.setCode(Constants.SUCCESS_CODE);
        returnBase.setMsg(Constants.SUCCESS_MSG);
        returnBase.setPath(path);
        returnBase.setType("request");
        return returnBase;
    }

    public static WebSocketReturnBase succeedMsg(String type, String path, int returnCode, String returnMsg) {
        WebSocketReturnBase returnBase = new WebSocketReturnBase<>();
        returnBase.setCode(returnCode);
        returnBase.setMsg(returnMsg);
        returnBase.setPath(path);
        returnBase.setType(type);
        return returnBase;
    }

    public static <W> WebSocketReturnBase senddMsg(String type, String path, int returnCode, String returnMsg, W w) {
        WebSocketReturnBase returnBase = new WebSocketReturnBase<>();
        returnBase.setCode(returnCode);
        returnBase.setMsg(returnMsg);
        returnBase.setPath(path);
        returnBase.setData(w);
        returnBase.setType(type);
        return returnBase;
    }

    public static WebSocketReturnBase error(String path, int returnCode, String returnMsg) {
        WebSocketReturnBase returnBase = new WebSocketReturnBase<>();
        returnBase.setCode(returnCode);
        returnBase.setMsg(returnMsg);
        returnBase.setData(null);
        returnBase.setPath(path);
        returnBase.setType("request");
        return returnBase;
    }


}
